const htmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
module.exports = {
	context: __dirname,

	entry:'./src/script/main.js',

	output:{
		path: path.resolve(__dirname,'dist/js'),
		filename:'bundle.js'
	},
	module: {
        //加载器配置
        loaders: [
        	//.js 文件使用 badel-loader
        	{ 
        		test: /\.js$/, 
        		loader: 'babel-loader', 
        		include: path.resolve(__dirname,'src'),
        		exclude: path.resolve(__dirname,'node_modules'),        	
        		query:{
        			presets:['latest']
        		}
        	},
        	//.html 模版文件使用 html-loader
        	{
        		test: /\.html$/,
        		loader: 'html-loader'
        	},
            // .css 文件使用 style-loader 和 css-loader 来处理
            { 
            	test: /\.css$/,
            	loader: 'style-loader!css-loader?importLoaders=1!postcss-loader'
            },            
            //.scss 文件使用 style-loader、css-loader 和 sass-loader 来编译处理
            {
            	test: /\.less$/,
            	loader: 'style-loader!css-loader!postcss-loader!less-loader'
            },            
            //图片文件使用 url-loader 来处理，小于8kb的直接转为base64
            { 
            	test: /\.(gif|png|jpe?g|svg|webp)$/i,
            	loader: [
            		'url-loader?limit=8192&name=assets/[hash:5].[ext]',
            		'image-webpack-loader'
            	]
            }
        ]
    },
	plugins:[
		new htmlWebpackPlugin({
			filename:'index.html',
			template:'index.html',
			inject:'body'			
		})	
	]
}